﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace PRE.Report
{
    public partial class FrmDSSV : DevExpress.XtraEditors.XtraForm
    {
        ServiceReference_SV.Service1SoapClient sr_sv = new ServiceReference_SV.Service1SoapClient();
        ServiceReference_Lophoc.WS_LophocSoapClient sr_lophoc = new ServiceReference_Lophoc.WS_LophocSoapClient();

        IList<ServiceReference_SV.Sinhvien> tb_sv;

        public FrmDSSV()
        {
            InitializeComponent();
        }

        private void FrmDSSV_Load(object sender, EventArgs e)
        {
            var tb_lop = (IList<ServiceReference_Lophoc.Lophoc>)sr_lophoc.SelectLophoc();
            if(tb_lop != null)  
                cboLophoc.Properties.DataSource = tb_lop;
        }

        private void cboLophoc_EditValueChanged(object sender, EventArgs e)
        {
            int lophoc_id = Convert.ToInt32(cboLophoc.EditValue);
            tb_sv = (IList<ServiceReference_SV.Sinhvien>)sr_sv.Select_SV_Lop(lophoc_id);
            if (tb_sv != null)
                grcMain.DataSource = tb_sv;
        }

        private void btnPrint_Click(object sender, EventArgs e)
        {
            var frm = new FrmReport();
            frm.Text = "In Danh sách sinh viên";
            var rpt = new XR_DSSV();

            //DataTable dtb = WS.UTL.BaseUTL.ListToDataTable(_tb);
            int lophoc_id = Convert.ToInt32(cboLophoc.EditValue);
            tb_sv = (IList<ServiceReference_SV.Sinhvien>)sr_sv.Select_SV_Lop(lophoc_id);
            DataTable dtb = WS.UTL.BaseUTL.IListToDataTable(tb_sv);

            rpt.DataSource = dtb;
            frm.SetReport(rpt);
            frm.Show();
            frm.Activate();
       //     this.Close();
        }
    }
}